<?php


namespace Tbf\Bundle\UpyunBundle;


use Tbf\Bundle\UploadBundle\BlobInterface;
use Tbf\Bundle\UploadBundle\error;
use Tbf\Bundle\UploadBundle\SaverInterface;
use Tbf\Bundle\UploadBundle\url;
use Tbf\Bundle\UpyunBundle\Model\UpYun;

class UpyunSaver implements SaverInterface{
    protected $upyun;
    protected $save_path;
    protected $save_url;
    function __construct(UpYun $upyun,$save_path,$save_url){
        $this->upyun = $upyun;
        $this->save_path = $save_path;
        $this->save_url = $save_url;
    }
    /**
     * @param  BlobInterface $blob
     * @return url
     * @return error
     */
    public function save(BlobInterface $blob)
    {
        list($content,$err) = $blob->getContent();
        if ($err!==null) {
            return array(null,$err);
        }
        $this->upyun->uploadContentByPhp($this->save_path,$content);
        if ($err!==null) {
            return array(null,$err);
        }
        return array($this->save_url,null);
    }

}